package com.kj.xuyuan;

import android.os.Build;

import com.kj.xuyuan.adapter.MainPageAdapter;
import com.kj.xuyuan.chat.MyConversationListFragment;
import com.kj.xuyuan.home.HomeFragment;
import com.kj.xuyuan.matchmaker.MatchMakerFragment;
import com.kj.xuyuan.mine.MineFragment;
import com.kj.xuyuan.widget.NoScrollViewPager;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;

@RequiresApi(api = Build.VERSION_CODES.M)
public class MainPageController {
    private MainActivity context;
    private NoScrollViewPager vpContent;
    private List<Fragment> fragments;

    public MainPageController(MainActivity context, NoScrollViewPager vp) {
        this.context = context;
        this.vpContent = vp;
        fragments = new ArrayList<>();
        initViews();
    }

    private void initViews() {
        fragments.add(new HomeFragment());
        fragments.add(new MatchMakerFragment());
        fragments.add(new MyConversationListFragment());
        fragments.add(new MineFragment());
        MainPageAdapter mAdapter = new MainPageAdapter(context.getSupportFragmentManager(), fragments);
        //设置当前可见Item左右可见page数，次范围内不会被销毁
        vpContent.setOffscreenPageLimit(0);
        vpContent.setAdapter(mAdapter);
    }

    public void ChangePage(int position) {
        vpContent.setCurrentItem(position);
    }

}
